package com.tastyshop.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tastyshop.dao.NoticeBoardMapper;
import com.tastyshop.domain.NoticeBoard;

@Transactional
@Service
public class NoticeBoardServiceImpl implements NoticeBoardService{
	
	@Autowired
	private NoticeBoardMapper mapper;

	@Override
	public List<NoticeBoard> getNoticeList(String field, String keyword,
			int page, int rows) {
		Map<Object, Object> params = new HashMap<Object, Object>();
		params.put("field", field);
		if(!"".equals(keyword)){
			params.put("keyword", keyword);
		}else{
			params.put("keyword", "");
		}
		params.put("page", page);
		params.put("rows", rows);
		return mapper.getNoticeList(params);
	}

	@Override
	public void noticeInsert(NoticeBoard noticeBoard) {
		mapper.noticeInsert(noticeBoard);		
	}

	@Override
	public void hitCount(Integer idx) {
		mapper.hitCount(idx);
	}

	@Override
	public void noticeModify(NoticeBoard noticeBoard) {
		mapper.noticeModify(noticeBoard);
	}

	@Override
	public void noticeDelete(Integer idx) {
		mapper.noticeDelete(idx);
		
	}

	@Override
	public HashMap<String, NoticeBoard> getInfo(int idx) {
		HashMap<String, NoticeBoard> map = new HashMap<>();
		map.put("noticeBoard", mapper.getInfo(idx));
		map.put("prev", mapper.getPrev(idx));
		map.put("next", mapper.getNext(idx));
		return map;
	}

	@Override
	public NoticeBoard noticeView(Integer idx) {
		return mapper.noticeView(idx);
	}

}
